const cp = require('child_process'),
      data = require('./npmlist.json');
exports.main = (req,res) =>{    
    const tool = require(req.bind.dir+'/module/emma.js');
    var HTML = tool.require('html');
    //const mime = tool.local('mime');
    var h = new HTML();
    h.isMobile(req,tool);
    h.appHead('<meta charset="utf-8">');
    h.load({title:"NPM 安装记录"});
    var xhtml = `
        <nav>
            <a href="/index">Home</a>
        </nav>
    `;
    //console.log(cp.execSync('npm list').toString());
    xhtml += printNpm();
    h.appBody(xhtml);
    res.write(h.getHtml());
    tool.clear(__dirname+'/npmlist.json');
}
//  打印 npm 安装清单
function printNpm()
{
    var xhtml = '',
        d,
        npm = data['npm'];
    for(var k in npm){
        xhtml += `<h4>${k}</h4>`;
        d = npm[k];
        for(var k1 in d){
            xhtml += `<li>${k1} ：${d[k1]}</li>`;
        }
    }
    return xhtml;
}